var t = getApp();

Page({
    data: {
        info: [],
        id: "",
        many_form: [],
        once_form: !1,
        member: [],
        order: [],
        card: [],
        checked: "",
        manyStatus: !1,
        merchant: !1
    },
    onLoad: function(t) {
        t.id && (this.data.id = t.id);
        var e = decodeURIComponent(t.scene);
        if (e) {
            console.log(e);
            var a = [];
            a = e.split(",");
            for (var n = 0; n < a.length; n++) {
                var o;
                o = a[n].split("="), console.log(o), "id" == o[0] && (this.data.id = o[1]);
            }
        }
        this.getData();
    },
    stepChange: function(t) {
        var e = t.currentTarget.dataset.index;
        if (console.log(t.detail), this.data.many_form[e]) this.data.many_form[e].num = t.detail; else {
            var a = this.data.info;
            a.member_many[e].num = t.detail, this.setData({
                info: a
            });
        }
    },
    onceChange: function(t) {
        this.setData({
            once_form: t.detail
        });
    },
    manyChange: function(t) {
        var e = t.currentTarget.dataset, a = e.index, n = e.item;
        if (console.log(n, n.checked), t.detail) {
            this.data.manyStatus = !0;
            var o = {
                id: n.id,
                num: n.num
            };
            this.data.many_form[a] = o, console.log(this.many_form, "true");
        } else this.data.many_form.splice(a, "1");
        var r = this.data.info;
        r.member_many[a].checked = t.detail, this.setData({
            info: r
        });
    },
    getData: function() {
        var e = this, a = t.getNetAddresss("plugin.customer-development.Frontend.controllers.write-off.store");
        t._getNetWork({
            url: a,
            data: {
                id: this.data.id
            },
            success: function(a) {
                var n = a.data;
                if (1 != n.result) return t.tips(n.msg);
                var o = n.data;
                if (o.member_card.member_many) for (var r = 0; r < o.member_card.member_many.length; r++) o.member_card.member_many[r].num = 1;
                e.setData({
                    info: o.member_card,
                    member: o.member_card.member,
                    order: o.member_card.order,
                    card: o.member_card.card.goods
                }), wx.setNavigationBarTitle({
                    title: o.plugin_name ? o.plugin_name : "拓客卡"
                });
            }
        });
    },
    submit: function() {
        var e = this;
        if (!this.data.once_form && !this.data.manyStatus) return t.tips("请选择核销内容");
        wx.showModal({
            content: "是否确认核销",
            success: function(t) {
                t.confirm ? e.submitGet() : t.cancel && console.log("用户点击取消");
            }
        });
    },
    submitGet: function() {
        var e = this, a = {
            id: this.data.id,
            once: this.data.once_form ? this.data.once_form : "",
            many: this.data.manyStatus ? this.data.many_form : ""
        }, n = t.getNetAddresss("plugin.customer-development.Frontend.controllers.write-off.store-handle");
        t._postNetWork({
            url: n,
            data: a,
            success: function(a) {
                var n = a.data;
                if (1 != n.result) return t.tips(n.msg);
                e.setData({
                    merchant: !0
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});